home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / forth / amiga / amigaker.arc / 12.parsing < prev    next >
Text File  |  1987-12-30  |  6KB  |  158 lines

  1. ;
  2. ;  12.parsing
  3. ;
  4. ;  Deals with input and stream processing.
  5. ;
  6.  
  7. * skip            (s addr len char -- addr' len' ) Skips over char, while
  8. ; it is found. Returns the remaining length and the address.
  9.                   dc.w     -1
  10.                   dc.l     link3
  11. link3             set      *-4
  12.                   dc.b     $84,'ski',$80!'p'
  13.                   cnop     0,2
  14. _skip             dc.l     *+4
  15.                   movem.l  (sp)+,d0-d1/a0    ;d0=char,d1=len,a0=adr
  16.                   ori      #%00100,ccr       ;set z to indicate a match
  17.                   bra.s    2$                ;enter loop at end, to 
  18. 1$                cmp.b    (a0)+,d0          ;  allow for 0 length
  19. 2$                dbne     d1,1$             ;
  20.                   addq.w   #1,d1             ;adjust count
  21.                   beq.s    3$                ; and if it's 0,adr is correct
  22.                   subq.l   #1,a0             ; else adjust address
  23. 3$                move.l   a0,-(sp)
  24.                   move.l   d1,-(sp)
  25.                   jmp      (a3)
  26.  
  27. * scan            (s addr len char -- addr' len' ) Search for char in the
  28. ; string. Leave address of the match and the remaining length.
  29.                   dc.w     -1
  30.                   dc.l     link3
  31. link3             set      *-4
  32.                   dc.b     $84,'sca',$80!'n'
  33.                   cnop     0,2
  34. _scan             dc.l     *+4
  35.                   movem.l  (sp)+,d0-d1/a0
  36.                   andi     #%11011,ccr       ;clr z to indicate no match
  37.                   bra.s    2$
  38. 1$                cmp.b    (a0)+,d0
  39. 2$                dbeq     d1,1$
  40.                   addq.w   #1,d1
  41.                   beq.s    3$
  42.                   subq.l   #1,a0
  43. 3$                move.l   a0,-(sp)
  44.                   move.l   d1,-(sp)
  45.                   jmp      (a3)
  46.  
  47. * /string         (s addr len n -- addr' len' ) Index into string by n
  48.                   dc.w     -1
  49.                   dc.l     link3
  50. link3             set      *-4
  51.                   dc.b     $87,'/strin',$80!'g'
  52.                   cnop     0,2
  53. _slash_string     dc.l     nest
  54.                   dc.l     _over,_min,_rot,_over,_plus
  55.                   dc.l     _minus_rot,_minus,_exit
  56.  
  57. * place           (s addr len to -- ) copy the string to 'to' and place
  58. ; the length byte in front of it. ( requires len+1 storage space )
  59.                   dc.w     -1
  60.                   dc.l     link0
  61. link0             set      *-4
  62.                   dc.b     $85,'plac',$80!'e'
  63.                   cnop     0,2
  64. _place            dc.l     nest
  65.                   dc.l     _3dup,_1_plus,_swap,_move,_c_store
  66.                   dc.l     _drop,_exit
  67.  
  68. * (source)        (s -- addr len ) Returns the string to be scanned. The
  69. ; default for source.
  70.                   dc.w     -1
  71.                   dc.l     link0
  72. link0             set      *-4
  73.                   dc.b     $88,'(source',$80!')'
  74.                   cnop     0,2
  75. _nest_source      dc.l     nest
  76.                   dc.l     _loading,_fetch
  77.                   dc.l     _question_branch,1$
  78.                   dc.l     _lb,_fetch,_4_plus,_count,_branch,2$
  79. 1$                dc.l     _tib,_number_tib,_fetch
  80. 2$                dc.l     _exit
  81.  
  82. * source          The deferred source.
  83.                   dc.w     -1
  84.                   dc.l     link3
  85. link3             set      *-4
  86.                   dc.b     $86,'sourc',$80!'e'
  87.                   cnop     0,2
  88. _source           dc.l     dodefer,_nest_source
  89.  
  90. * parse-word      (s char -- addr len ) Skip leading char's, then scan
  91. ; for the next char, return the enclosed string. Updates '>in'
  92.                   dc.w     -1
  93.                   dc.l     link0
  94. link0             set      *-4
  95.                   dc.b     $8a,'parse-wor',$80!'d'
  96.                   cnop     0,2
  97. _parse_word       dc.l     nest
  98.                   dc.l     _to_r,_source,_tuck,_to_in,_fetch
  99.                   dc.l     _slash_string,_r_fetch,_skip,_over
  100.                   dc.l     _swap,_r_from,_scan,_to_r,_over
  101.                   dc.l     _minus,_rot,_r_from,_dup,_0_notequal
  102.                   dc.l     _plus,_minus,_to_in,_store,_exit
  103.  
  104. * parse           (s char -- addr len ) Scan the input stream until char
  105. ; is found. Updates '>in'
  106.                   dc.w     -1
  107.                   dc.l     link0
  108. link0             set      *-4
  109.                   dc.b     $85,'pars',$80!'e'
  110.                   cnop     0,2
  111. _parse            dc.l     nest
  112.                   dc.l     _to_r,_source,_to_in,_fetch,_slash_string
  113.                   dc.l     _over,_swap,_r_from,_scan
  114.                   dc.l     _to_r,_over,_minus,_dup,_r_from
  115.                   dc.l     _0_notequal,_minus,_to_in,_plus_store,_exit
  116.  
  117. * 'word           (s -- addr ) Leaves the address where words are put.
  118.                   dc.w     -1
  119.                   dc.l     link0
  120. link0             set      *-4
  121.                   dc.b     $85,$27,'wor',$80!'d'
  122.                   cnop     0,2
  123. _tick_word        dc.l     nest
  124.                   dc.l     _here,_exit
  125.  
  126. * word            (s char -- addr ) Parse the input stream for char and
  127. ; return a count delimited string at here. NOTE: there is alway a NULL
  128. ; following it.
  129.                   dc.w     -1
  130.                   dc.l     link3
  131. link3             set      *-4
  132.                   dc.b     $84,'wor',$80!'d'
  133.                   cnop     0,2
  134. _word             dc.l     nest
  135.                   dc.l     _parse_word,_tick_word,_place
  136.                   dc.l     _tick_word,_dup,_count,_plus
  137.                   dc.l     _0,_swap,_c_store,_exit
  138.  
  139. * .(              (s -- ) Type the following string on the terminal.
  140.                   dc.w     -1
  141.                   dc.l     link2
  142. link2             set      *-4
  143.                   dc.b     $82!immediate,'.',$80!'('
  144.                   cnop     0,2
  145. _dot_paren        dc.l     nest
  146.                   dc.l     _nest_lit,')',_parse,_type,_exit
  147.  
  148. * (               (s -- ) skip the comment enclosed by ( ) combination.
  149.                   dc.w     -1
  150.                   dc.l     link0
  151. link0             set      *-4
  152.                   dc.b     $81!immediate,$80!'('
  153.                   cnop     0,2
  154. _paren            dc.l     nest
  155.                   dc.l     _nest_lit,')',_parse,_2drop,_exit
  156.  
  157.  
  158.